package cn.edu.scau.cmi.dengyu.client;

import cn.edu.scau.cmi.dengyu.singleton.Chairman;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;

public class SingletonPane extends Application{
	private static TextArea taDescription = new TextArea();
	Stage stage = new Stage();

	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		BorderPane pane = new BorderPane();
		pane.setCenter(getHBox());
		pane.setBottom(taDescription);
		Scene scene = new Scene(pane, 800, 400);
		primaryStage.setTitle("实验一 单例模式（主席创建）");
		primaryStage.setScene(scene);
		primaryStage.show();
		
	}
	
	private HBox getHBox(){
		HBox hBox = new HBox(15);
		hBox.setPadding(new Insets(15,5,5,5));
		Label lb = new Label("请输入要创建的主席名称：");
		TextField tf = new TextField();
		Chairman chairman1 = Chairman.getInstance("毛泽东");
		Button btChairman = new Button("创建主席");
		btChairman.setOnAction(e -> setDisplayText(tf.getText()));
		hBox.getChildren().addAll(lb,tf, btChairman);
		return hBox;
	}
	
	private void setDisplayText(String str) {
		taDescription.setText("想创建的主席名称为：" + str + "\n" 
				+ "现在主席的名字：" + Chairman.getInstance(str).getName());
		
	}
	public static void main(String[] args) {
		Application.launch(args);
	}
	
	public void showWindow() throws Exception {
		start(stage);
	}
	
}
